package com.yuanyi.changyihao.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 工具包，用来获得AccessToken
 */
public class AccessTokenUtil {

    static String AccessToken;
    static final String APPID = "wx3f1836a312ad0a8a";
    static final String APPSECRET = "dd69f27c18adf43136b118b1145c5d60";

    public static void main(String[] args) throws Exception{
        URL url = new URL("https://api.weixin.qq.com/cgi-bin/token?" +
                "grant_type=client_credential&appid=" + APPID + "&secret=" + APPSECRET);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();


        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"));
        String str;
        StringBuffer sb = new StringBuffer();
        while ((str = br.readLine()) != null) {
            sb.append(str);
        }
        System.out.println(sb);
    }

    public static void findAccessToken() throws IOException {
        URL url = new URL("https://api.weixin.qq.com/cgi-bin/token?" +
                "grant_type=client_credential&appid=" + APPID + "&secret=" + APPSECRET);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();


        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"));
        String str;
        StringBuffer sb = new StringBuffer();
        while ((str = br.readLine()) != null) {
            sb.append(str);
        }
        System.out.println(sb);

    }
}
